﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using DBHelper;
using BusinessLayer.WorldArtPrice.Models;

namespace BusinessLayer.WorldArtPrice
{
    public class AuctionBL
    {
        private readonly DbHelper _db;

        public AuctionBL()
        {
            _db = new DbHelper(new DbConfig().DbAuctionConnectionString);         
        }

        public List<AuctionHouseModel> GetAllAuctionHouse()
        {
            var oCommand = new SqlCommand("sp_TB_Upcoming_SelectAuctionHouse") { CommandType = CommandType.StoredProcedure };
            var list = _db.GetList<AuctionHouseModel>(oCommand);
            return list;           
        }
        public List<AuctionCountryModel> GetAllAuctionCountry()
        {
            var oCommand = new SqlCommand("sp_TB_Upcoming_SelectCountry") { CommandType = CommandType.StoredProcedure };
            var list = _db.GetList<AuctionCountryModel>(oCommand);
            return list;
        }
        public List<AuctionModel> Search(string auctionHouse, string country, string fdatelay, int pageIndex, int pageSize, out int totalRecord)
        {
            var oCommand = new SqlCommand("sp_TB_Upcoming_Search") { CommandType = CommandType.StoredProcedure };
            oCommand.Parameters.Add(new SqlParameter("@AuctionHouse", auctionHouse));
            oCommand.Parameters.Add(new SqlParameter("@Country", country));
            oCommand.Parameters.Add(new SqlParameter("@Fdatelay", fdatelay));
            oCommand.Parameters.Add(new SqlParameter("@PageIndex", pageIndex));
            oCommand.Parameters.Add(new SqlParameter("@PageSize", pageSize));
            var output = new SqlParameter("@TotalRecord", SqlDbType.Int) { Direction = ParameterDirection.Output };
            oCommand.Parameters.Add(output);
            var list = _db.GetList<AuctionModel>(oCommand);
            totalRecord = (int)output.Value;
            return list;
        }
    }
}
